<header class="layout head padding-small">
    <a href="javascript:pageBack();" class="hBack float-left"></a>
    <h4 class="hTxt float-left text-center text-white">我的订单</h4>
    <a href="javascript:;" id="btnJdkey" class="hHlep float-right"></a>
</header>
<script type="text/javascript">
	$(function(){
		$(window).scroll(function(){
			var $header = $('header');
			if($(window).scrollTop() >= 44){
				$header.hide();
			}else{
				$header.show();
			};
		});
	})
</script>
<!--搜索框S-->
<div class="padding layout fixed">
<div class="radius-big bg-white border border-ef7f7e mem-o-select">
    <div class="x3">
        <form id="search_order" method="get">
            <input type="hidden" name="act" value="member_order">
        <select class="border-none padding-small text-small layout" name="state_type" id="state_type">
            <option value="all" <?php echo $_GET['state_type']=='all'?'selected':''; ?>>所有订单</option>
            <option value="order_pay" <?php echo $_GET['state_type']=='order_pay'?'selected':''; ?>>待付款</option>
            <option value="order_pay_confirm" <?php echo $_GET['state_type']=='order_pay_confirm'?'selected':''; ?>>待卖家收款</option>
            <option value="order_no_shipping" <?php echo $_GET['state_type']=='order_no_shipping'?'selected':''; ?>>待发货</option>
            <option value="order_shipping" <?php echo $_GET['state_type']=='order_shipping'?'selected':''; ?>>已发货</option>
            <option value="order_finish" <?php echo $_GET['state_type']=='order_finish'?'selected':''; ?>>已完成</option>
            <option value="order_cancal" <?php echo $_GET['state_type']=='order_cancal'?'selected':''; ?>>已取消</option>
            <option value="order_confirm" <?php echo $_GET['state_type']=='order_confirm'?'selected':''; ?>>已确认</option>
            <option value="noeval" <?php echo $_GET['state_type']=='noeval'?'selected':''; ?>>待评价</option>
        </select>
    </div>
    <div class="x8 padding-small">
        <span class="text-ef7f7e float-left">|</span>
        <input name="order_sn" value="<?php echo $_GET['order_sn']; ?>" class="border-none text-small padding-small-left x11" placeholder="请输入您想要搜索的订单号">
    </div>
    <input type="submit" class="x1 bg-red padding-small text-white text-center border-none " value="搜">
    </form>
</div>
</div>
<!--我的订单S-->
<?php if(!empty($output['order_array']) && is_array($output['order_array'])){?>
<?php foreach($output['order_array'] as $order_id=>$goods_arr){?>
<div class="bg-white  margin padding radius-big cart-list padding-bottom clearfix">
    <a href="javascript:;" class="sale-off clearfix">
        <i class="sale-icon float-left margin-left"></i>
        <span class="margin-left"><?php echo $goods_arr[0]['store_name']?></span>
    </a>
    <!--订单号 订单状态S-->
    <div class="padding-top clearfix">
        <div class="float-left">订单号：<span><?php echo $goods_arr[0]['order_sn']; ?></span></div>
        <div class="float-right text-red"><?php echo orderModel::orderStateInfo($goods_arr[0]['order_state'], $goods_arr[0]['refund_state']);?></div>
    </div>
    <!--订单号 订单状态E-->
    <!--商品列表S-->
    <ul class="sale-tab border radius margin-top padding-small">
        <?php foreach($goods_arr as $item){?>
        <li class="sale-tab-list">
            <a href="index.php?act=goods&goods_id=<?php echo $item['goods_id']?>" class="clearfix">
                <span class="goods-img float-left margin-small-right"><img src="<?php echo cthumb($item['goods_image'],'small',$item['store_id'])?>" onload="javascript:DrawImage(this,60,60);" ></span>
                <span class="goods-name margin-bottom text-small "><?php echo $item['goods_name']?></span>
                <span class="text-red"><i class="goods-price">￥<?php echo $item['goods_price']?></i> &times; <i class="salesNum"><?php echo $item['goods_num']?></i></span>
            </a>
        </li>
        <?php }?>
    </ul>
    <!--商品列表E-->

    <div class="sale-price padding-top text-small">订单总价 <?php if ($goods_arr[0]['shipping_fee'] > 0){?>(含<?php echo $goods_arr[0]['shipping_name']?$goods_arr[0]['shipping_name']:'运费';?> &yen;<?php echo $goods_arr[0]['shipping_fee'];?>)
        <?php }else{?>
           (免运费)
        <?php }?>：<span class="text-red text-big">&yen;<?php echo $goods_arr[0]['order_amount']; ?></span></div>
    <div class="padding-top clearfix">
        <?php if($goods_arr[0]['order_state'] == 0){?>
        <a href="javascript:delOneOrder(<?php echo $goods_arr[0]['order_id'];?>)" class="bg-red float-right radius text-small text-white margin-left padding-small">删除订单</a>
        <?php }?>
        <a href="index.php?act=member_order&op=orderDetail&order_id=<?php echo $goods_arr[0]['order_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">查看订单</a>
        <!--查看物流信息-->
        <?php  if($goods_arr[0]['shipping_mode'] == SHIPPING_MODE_DEFAULT && $goods_arr[0]['shipping_express_id'] > 0) { ?>
        <a href="index.php?act=member_order&op=show_express&order_id=<?php echo $goods_arr[0]['order_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">查看物流</a>
        <?php }elseif ($goods_arr[0]['shipping_mode'] == SHIPPING_MODE_MDT || $goods_arr[0]['shipping_mode'] ==SHIPPING_MODE_FDY) {
            if (empty($goods_arr[0]['shipping_express_id']) && ($goods_arr[0]['order_state'] >= 25||$goods_arr[0]['order_state']==11)) {
                ?><a href="index.php?act=member_order&op=show_express&order_id=<?php echo $goods_arr[0]['order_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">查看物流</a>
            <?php }elseif(!empty($goods_arr[0]['shipping_express_id']) && ($goods_arr[0]['order_state']>=30||$goods_arr[0]['order_state']==11)){?>
                <a href="index.php?act=member_order&op=show_express&order_id=<?php echo $goods_arr[0]['order_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">查看物流</a><?php }}?>

        <!--申请售后-->
        <?php
        $nine_days = time()-3600*24*ORDER_RETURN_DAY_LIMIT;//判断是否九天内
        //订单是否在规定期限内+订单是否确认收货或者不是货到付款
        if ($goods_arr[0]['add_time']>$nine_days && (($goods_arr[0]['order_cod']==0 && $goods_arr[0]['order_state'] >=20)||($goods_arr[0]['order_cod']==1&&($goods_arr[0]['order_state'] ==11||$goods_arr[0]['order_state']>=40))) && $goods_arr[0]['refund_state'] == 0 && $goods_arr[0]['return_state'] == 0) {
            ?>
            <a href="index.php?act=member_order&op=applysale&order_id=<?php echo $goods_arr[0]['order_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">申请售后</a>

        <?php } ?>
        <!------------------------------售后动态----------------退货退款-------------------------->
        <?php if($goods_arr[0]['return_state'] > 0 && $goods_arr[0]['refund_state'] > 0){?>
            <a href="index.php?act=member_order&op=return_view&return_id=<?php echo $goods_arr[0]['return']['return_id']; ?>&log_id=<?php echo $goods_arr[0]['refund']['log_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">售后动态</a>
        <?php }?>
        <!------------------------------售后动态----------------仅退款-------------------------->
        <?php if(!$goods_arr[0]['return_state'] > 0 && $goods_arr[0]['refund_state'] > 0){?>
            <a href="index.php?act=member_order&op=refund_view&log_id=<?php echo $goods_arr[0]['refund']['log_id']; ?>" class="bg-red float-right radius text-small text-white margin-left padding-small">售后动态（仅退款）</a>
        <?php }?>
        <!--买家确认收货-->
        <?php if ($goods_arr[0]['refund_state'] == 0 && $goods_arr[0]['order_state'] == 30) { ?>
            <?php if ($goods_arr[0]['payment_direct'] == '1'){?>
                <a href="javascript:void()" data-toggle="click" data-target="#confirm_receive" data-mask="1" data-width="80%" onclick="changeId(<?php echo $goods_arr[0]['order_sn'];?>,<?php echo $goods_arr[0]['order_id']; ?>,1)" class="dialogs bg-red float-right radius text-small text-white margin-left padding-small">确认收货</a>
            <?php }?>
        <?php } ?>
        <!--取消订单/付款-->
        <?php if ($goods_arr[0]['order_state'] == 10) { ?>
            <a href="javascript:void()"  data-toggle="click" data-target="#cancel_order" data-mask="1" data-width="80%" onclick="changeId(<?php echo $goods_arr[0]['order_sn'];?>,<?php echo $goods_arr[0]['order_id']; ?>,0)" class="dialogs bg-red float-right radius text-small text-white margin-left padding-small">取消订单</a>
        <?php }?>
        <?php if ($goods_arr[0]['order_state'] == 10 && $goods_arr[0]['order_cod'] == 0) { ?>
            <a href="index.php?act=order&op=order_pay&order_id=<?php echo $goods_arr[0]['order_id']; ?>"  class="bg-red float-right radius text-small text-white margin-left padding-small"> 付款</a>
        <?php } ?>

        <!-- 货到付款订单取消开始-->
        <?php if(($goods_arr[0]['order_cod'] == 1 && $goods_arr[0]['order_state'] == 15)|| ($goods_arr[0]['order_cod'] == 1 && $goods_arr[0]['order_send'] == 0 && $goods_arr[0]['order_state'] != 0)){?>
            <!-- <a href="javascript:void()" paytype="iscash" onclick="changeCashId(this,<?php echo $goods_arr[0]['order_sn'];?>,<?php echo $goods_arr[0]['order_id']; ?>,0)">取消订单</a> -->
            <a href="javascript:void()" data-toggle="click" data-target="#cancel_order" data-mask="1" data-width="80%" onclick="changeId(<?php echo $goods_arr[0]['order_sn'];?>,<?php echo $goods_arr[0]['order_id']; ?>,0)"  class="dialogs bg-red float-right radius text-small text-white margin-left padding-small"> 取消订单</a>
        <?php }?>
        <!-- 货到付款订单取消结束-->
        <!--评价-->
        <?php if (($goods_arr[0]['order_state'] == 40) && $goods_arr[0]['refund_state'] < 2 && $goods_arr[0]['able_evaluate']) { ?>
            <a href="index.php?act=member_evaluate&op=add&order_id=<?php echo $goods_arr[0]['order_id']?>"  class="bg-red float-right radius text-small text-white margin-left padding-small"> 我要评价</a>
        <?php } ?>
    </div>
</div>
<?php }?>
    <?php include 'page.php';?>
<!--我的订单E-->
<?php }else{?>
    <div class="noTxt text-center text-gray padding-large">
        <i class="icon-meh-o"></i>
        <?php if(isset($_GET['state_type'])){?>
            <p>暂无结果</p>
        <?php }else{?>
        <p>您还没有购买过任何商品哦，<br><a href="index.php?act=official_shop" class="text-ef7f7e">随便逛逛</a>可能会遇到喜欢的商品呢(:</p>
        <?php }?>
    </div>
<?php }?>
<!-- 取消定单对话框内容 -->
<div id="cancel_order" >
<div class="dialog">
    <div class="dialog-head">
        <span class="close rotate-hover"></span>
        <strong>您确定要取消下面的订单吗?</strong>
    </div>
    <form method="get">
        <input type="hidden" name="act" value="member_order" />
        <input type="hidden" name="op" value="change_state" />
        <input type="hidden" name="state_type" value="cancel_order" />
        <input type="hidden" name="order_id" id="order_id" value="" />
        <input type="hidden" name="paytype" id="paytype" value="" />
    <div class="dialog-body">
        <p>订单号：<span id="order_sn"></span></p>
        <dl>
            <dt>取消原因：</dt>
            <dd>
                <ul class="">
                    <li>
                        <label> <input type="radio" checked name="state_info" id="d1" value="改买其它商品" />
                        改买其它商品</label>
                    </li>
                    <li>
                        <label>   <input type="radio" name="state_info" id="d2" value="改用其它配送方式" />
                       改用其它配送方式</label>
                    </li>
                    <li>
                        <label> <input type="radio" name="state_info" id="d3" value="从其它商城购买" />
                       从其它商城购买</label>
                    </li>
                    <li>
                        <label><input type="radio" name="state_info" id="d4" value="其它原因" />
                        其它原因</label>
                    </li>
                    <li id="other_reason">
                        <textarea name="state_info1" rows="3" id="other_reason_input"></textarea>
                    </li>
                </ul>
            </dd>
        </dl></div>
    <div class="dialog-foot">
        <button type="button" class="button dialog-close">取消</button>
        <button class="button bg-green">确认</button>
    </div>
    </form>
</div>

</div>

<!-- 确认收货对话框内容 -->
<div id="confirm_receive">
    <div class="dialog">
        <div class="dialog-head">
            <span class="close rotate-hover"></span>
            <strong>您是否确认已收到以下订单的商品?</strong>
        </div>
        <form  method="get" >
            <input type="hidden" name="act" value="member_order" />
            <input type="hidden" name="op" value="change_state" />
            <input type="hidden" name="state_type" value="confirm_order" />
            <input type="hidden" name="order_id" id="order_id_t" value="" />
        <div class="dialog-body">
            <p >订单号：<span id="order_sn_t"></span></p>
            <dl>
                <p class="text-dot">请注意： 如果你尚未收到商品请不要点击“确定”。大部分被骗案件都是由于提前确认付款被骗的，请谨慎操作！</p>
            </dl></div>
        <div class="dialog-foot">
            <button type="button" class="button dialog-close">取消</button>
            <button class="button bg-green">确认</button>
        </div>
    </div>
    </div>



<script type="text/javascript">
    //搜索下拉事件
    $('#state_type').change(function(){
        $('#search_order').submit();
    });

    //货到付款订单取消特有
    function changeCashId(obj,order_sn,order_id,type){
        if(type == 0){
            $('#order_sn').html(order_sn);
            $('#order_id').val(order_id);
            var paytype=$(obj).attr('paytype');
            $("#paytype").val(paytype);
        }else if(type == 1){
            $('#order_sn_t').html(order_sn);
            $('#order_id_t').val(order_id);
        }
    }


    (function(){
        selChange=function (obj) {
            if($(obj).hasClass('checked')){
                $(obj).removeClass('checked');
            }else{
                $(obj).addClass('checked');
            }
        }
        selAll = function(obj){
            if($(obj).hasClass('checked')){
                $('.checkbox').removeClass('checked');
            }else{
                $('.checkbox').addClass('checked');
            }
        }
        $(document).ready(function (e) {
            $('#hbzf').click(function(){
                var url = 'index.php?act=order&op=order_pay';
                var order_id = '';
                $(".checkbox").each(function () {
                    if ($(this).hasClass('checked') && $(this).data('order_id') != 'undefined' && $(this).data('order_id') != null) {
                        order_id += '&order_id[]=' + $(this).data('order_id');
                    }
                });
                window.location = url + order_id;
            });
        });
    })();
    //删除定单方法
    function delOneOrder(order_id){
        if(!confirm('删除订单后将不能再找回，确定删除吗？')){return false;}
        //ajax删除定单
        $.getJSON('index.php?act=member_order&op=ajax_del_order',{order_id:order_id},function(data){
            if(data.state==true){
                alert(data.msg);
                window.location.reload(true);
            }else{
                alert(data.msg);
            }
        });
    }
    //取消定单或确认收货
    function changeId(order_sn,order_id,type){
        if(type == 0){
            $('#order_sn').html(order_sn);
            $('#order_id').val(order_id);
        }else if(type == 1){
            $('#order_sn_t').html(order_sn);
            $('#order_id_t').val(order_id);
        }
    }

</script>

